package com.aier.admin.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.aier.admin.common.AdminFinalPageSize;
import com.aier.admin.service.IAdminVideoService;
import com.aier.common.dao.ICommonDAO;
import com.aier.entrance.common.EntranceServerData;
import com.aier.entrance.entity.VideoDevice;

/**
 * 后台管理门禁设备的管理 包含添加门禁设备信息(entradd),删除门禁信息
 * (entrdelete),修改门禁信息(entrupdate),显示门禁信息(entrlist)
 * 
 * @author sun
 * 
 */
@Scope("prototype")
@Component("adminVedioAssignAction")
public class AdminVedioAssignAction extends AdminBaseAction {

    private static final long serialVersionUID = 1L;

    @Resource(name = "adminVideoService")
    private IAdminVideoService adminVideoService;

    private List<VideoDevice> vilist;
    private Map<Short, String> vs = EntranceServerData.videoSupplier;
    // 当前页
    private int page;
    // 每页显示记录数
    private int page_size;
    // 总页数
    private int page_count;
    // 总数
    private int count;
    
    //状态
    private int s;
    
    //视频设备id
    private Long vid;
    //厂商id
    private Integer pid;

    @Override
    public String execute() {
        return SUCCESS;
    }
    
    /**
     * 显示未分派的视频信息
     */
    @SuppressWarnings("unchecked")
    public String unassignvideo() {
        if (page <= 0) {
            page = 1;
        }
        Map<String, Object> map = null;
        map = adminVideoService.selectUnassignVideo(page, AdminFinalPageSize.UNALLOCATED_VIDEO_PAGESIZE);
        vilist = (List<VideoDevice>) map.get(ICommonDAO.OBJ_LIST);
        if (null == vilist) {
            s = 0;
            return SUCCESS;
        }
        page = (Integer) map.get(ICommonDAO.PAGE);
        page_size = (Integer) map.get(ICommonDAO.PAGE_SIZE);
        page_count = (Integer) map.get(ICommonDAO.PAGE_COUNT);
        count = (Integer) map.get(ICommonDAO.COUNT);
        s = 1;
        return SUCCESS;
    }
    
    /**
     * 显示已分派的视频信息
     */
    @SuppressWarnings("unchecked")
    public String allocationvideo(){
        if (page <= 0) {
            page = 1;
        }
        Map<String, Object> map = null;
        map = adminVideoService.selectAllocationVideo(page, AdminFinalPageSize.ALLOCATION_VIDEO_PAGESIZE);
        vilist = (List<VideoDevice>) map.get(ICommonDAO.OBJ_LIST);
        if (null == vilist) {
            s = 0;
            return SUCCESS;
        }
        page = (Integer) map.get(ICommonDAO.PAGE);
        page_size = (Integer) map.get(ICommonDAO.PAGE_SIZE);
        page_count = (Integer) map.get(ICommonDAO.PAGE_COUNT);
        count = (Integer) map.get(ICommonDAO.COUNT);
        s = 1;
        return SUCCESS;
    }
    
    /**
     * 根据vid分派视频设备
     * 
     * @return
     */
    public String updatepid() {
        if (pid != null) {
            s = adminVideoService.updatePidByVid(pid, vid);
        } else {
            s = 0;
        }
        return SUCCESS;
    }

    /**
     * 根据vid回收视频设备
     * 
     * @return
     */
    public String updatenullpid() {

        s = adminVideoService.updatePidByVid(null, vid);
        return SUCCESS;
    }

    public String assign() {
        return SUCCESS;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public List<VideoDevice> getVilist() {
        return vilist;
    }

    public int getPage_size() {
        return page_size;
    }

    public int getPage_count() {
        return page_count;
    }

    public int getCount() {
        return count;
    }

    public int getS() {
        return s;
    }

    public void setAdminVideoService(IAdminVideoService adminVideoService) {
        this.adminVideoService = adminVideoService;
    }

    public void setVid(Long vid) {
        this.vid = vid;
    }

    public void setPid(Integer pid) {
        this.pid = pid;
    }

    public Map<Short, String> getVs() {
        return vs;
    }



}
